<?php
class Db
{
	private $DBHost = '';	//数据库主机地址
	private $DBUsername = '';	//数据库用户名
	private $DBPassword = '';	//数据库密码
	private $Connection;	//活动连接
	private $DatabaseName = '';	//数据库名称
	private $ConnectionEstablished = false;	//建立连接
	private $Result = array();	//检索结果
	private $NumResults = 0;	//结果数量
	private $FieldInfo = null;	//
	
	/**
	* 默认使用a MySQL 数据库连接.
	* @param string $DBHost, 数据库主机
	* @param string $DBUsername, 数据库用户名
	* @param string $DBPassword, 数据库密码
	* @example $db = new DB('localhost', 'myuser', 'myp@ssw0rd');
	*/
	public function DB($DBHost, $DBUsername, $DBPassword)
	{
		$this->DBHost = $DBHost;
		$this->DBUsername = $DBUsername;
		$this->DBPassword = $DBPassword;
	}
	
	/**
	* Checks whether a given table exists in the current database.
	* @return bool, TRUE on success, FALSE on failure
	*/
	private function TableExists($Table)
	{
		$TableInDb = @mysql_query('SHOW TABLES FROM '.$this->DatabaseName.' LIKE "'.$Table.'"');
	
		if($TableInDb)
		{
			return (mysql_num_rows($TableInDb)==1);
		}
		else
		{ return false;
		}
	}
	
	/**
	 * 返回最后的 identity, 失败时返回false
	 * @return int|bool
	 */
	public function GetLatestID()
	{
		$query = @mysql_query('SELECT LAST_INSERT_ID() AS `ID`;');
	
		if($query)
		{
			$row = mysql_fetch_array($query);
			return (int)$row['ID'];
		}
		else
		{ return false;
		}
	}
	
	

}
?>